package main

import (
	"flag"
	"fmt"
	"grabcad_spider/grabcad"
	"grabcad_spider/task_process"
	"grabcad_spider/utils"
	"os"
	"os/signal"

	"github.com/gogf/gf/frame/g"
)

var gfcfgFile = flag.String("gffile", "config.yml", "the gf config file")
var gfcfgPath = flag.String("gfpath", "./etc", "the gf config file")

func main() {
	// ...
	g.Cfg().SetPath(*gfcfgPath)
	g.Cfg().SetFileName(*gfcfgFile)
	utils.LoadAccountFromExcel()

	taskServer := task_process.StartServer()
	var name string
	fmt.Println("请选择操作： 1. GRABCAD-LIST  4. EXCEL-Export")
	fmt.Scanf("%s", &name)

	c := make(chan os.Signal)
	signal.Notify(c)

	if name == "1" {
		// 100页 https://grabcad.com/library?page=1&per_page=100&time=all_time&sort=popular
		for i := 1; i <= 100; i++ {
			url := fmt.Sprintf("https://grabcad.com/library?page=%d&per_page=100&time=all_time&sort=popular", i)
			task_process.ProcessGetList(url)
		}

	} else if name == "2" {
		// 详情
		url := "https://grabcad.com/library/toyota-rav4-1"
		url = "https://grabcad.com/library/ram-lalla-3d-model-1"
		//
		//aa := utils.GetTitleFromUrl(url)
		//
		//fmt.Println(aa)

		grabcad.GetDetail(url)

	} else if name == "3" {
		url := "https://grabcad.com/library?page=1&per_page=100&time=all_time&sort=popular"
		//grabcad.GetList(url)
		task_process.ProcessGetList(url)
	} else if name == "4" {
		grabcad.ExportExcel()
	} else {
		fmt.Println("输入错误")
	}

	var name1 string
	fmt.Println("程序运行结束，按任意键退出")
	fmt.Scanf("%s", &name1)
	taskServer.Stop()

}
